﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Lab_1_Basic_MVC3.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult BMI(double weight = 0, double height = 0, double result = 0)
        {
            ViewBag.weight = weight;
            ViewBag.height = height;
            ViewBag.result = CalculateBMI(weight, height);

            return View();
        }

        private string CalculateBMI(double weight, double height)
        {
            string result = "";
            if (height == 0 || weight == 0)
            {
                return result = "Please insert weight and height for BMI calculation";
            }
            if ((height < 0) || (weight < 0))
            {
                return result = "Please insert positive weight and height values for BMI calculation";
            }
            result = "" + (weight) / (height * height) + "";
            ViewBag.result = result;
            return result;
        }
    }
}
